package org.reach.springframework.factory.support;

import org.reach.springframework.factory.BeanFactory;
import org.reach.springframework.factory.config.BeanDefinition;

/**
 * @author 尹志远
 * @desc
 * @Date 2024/2/4 13:17
 */
public abstract class AbstractSingletonBeanFactory extends DefaultSingletonBeanFactory implements BeanFactory {


    @Override
    public Object getBean(String name) {
        Object bean = getSingleton(name);
        if (bean != null) {
            return bean;
        }

        BeanDefinition beanDefinition = getBeanDefinition(name);
        return createBean(name, beanDefinition);
    }

    protected abstract BeanDefinition getBeanDefinition(String beanName);

    protected abstract Object createBean(String beanName, BeanDefinition beanDefinition);

}
